//
//  ClassifyListViewController.m
//  Happy Kitchen
//
//  Created by mac_chen on 15/3/7.
//  Copyright (c) 2015年 mac_chen. All rights reserved.
//

#import "ClassifyListViewController.h"

@interface ClassifyListViewController ()

@end

@implementation ClassifyListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 根据点击上一个面的item设置导航栏的标题
    self.navigationItem.title = self.cateListName;
    
    
    // 创建tableView对象
    self.classifyListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 49 - 64)];
    // 指定代理人
    self.classifyListTableView.dataSource = self;
    self.classifyListTableView.delegate = self;
    
    [self.view addSubview:self.classifyListTableView];
    
    
    // 初始化数组
    self.allListArr = [NSMutableArray array];
    
    // 将上一页面解析得到的数据, 再次解析 (因为数组中包含字典)
    for (NSMutableDictionary *dic in self.allClassifyListArr) {
        ClassifyList *classifyList = [[ClassifyList alloc] init];
        [classifyList setValuesForKeysWithDictionary:dic];
        [self.allListArr addObject:classifyList];
    }
    // 刷新tableView
    [self.classifyListTableView reloadData];
    
}
// cell的个行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.allClassifyListArr.count;
}
// cell的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdetifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdetifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdetifier];
    }
    
    // 设置每个cell后面显示向右的图标
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    // 向右的箭头前面显示内容
//    cell.detailTextLabel.text = @"菜谱";
    
    ClassifyList *classifyList = [self.allListArr objectAtIndex:indexPath.row];
    cell.textLabel.text = classifyList.Name;
    return cell;
}
// 点击cell跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ClassifyDetailViewController *classifyDetailVC = [[ClassifyDetailViewController alloc] init];
    
    ClassifyList *classifyList = [self.allListArr objectAtIndex:indexPath.row];
    // 将name的值传到下一个页面
    classifyDetailVC.titleName = classifyList.Name;
    // 将Id的值传到下一页面
    classifyDetailVC.listId = classifyList.Id;
    
    
    [self.navigationController pushViewController:classifyDetailVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
